export default {
  // form表单类名
  formBoxClass: '',
  // 编辑按钮类名
  formBtnClass: '',
  // 是否启动监听页面渲染
  isObserver: true,
  init (formBoxClass = 'FORMBOX', formBtnClass = 'FORMBTN', isObserver = true) {
    this.formBoxClass = formBoxClass
    this.formBtnClass = formBtnClass
    this.isObserver = isObserver

    this.setReadOnly()

    // 启动监听
    if (this.isObserver) {
      let observer = new MutationObserver(() => {
        this.setReadOnly()
      })

      let targetNode = document.querySelector('body')

      observer.observe(targetNode, {
        childList: true
      })
    }
  },
  setReadOnly () {
    // 设置表单元素禁用事件
    let es = document.querySelectorAll('.FORMBOX *')
    if (es.length) {
      for (let i = 0; i < es.length; i++) {
        es[i].style.pointerEvents = 'none'
      }
    }

    // 移除编辑按钮
    let btns = document.querySelectorAll('.FORMBTN')

    if (btns.length) {
      for (let i = 0; i < btns.length; i++) {
        btns[i].remove()
      }
    }
  }
}
